﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
// 郭嘉欣完成
namespace BirthdayPlan
{
    public partial class result1 : Form
    {
        public result1()
        {
            InitializeComponent();
        }

        //回到计算日期，重新选日期
        private void button1_Click(object sender, EventArgs e)
        {
            Input2 form1 = new Input2();
            form1.Show();
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            result2 form2 = new result2();
            form2.Show();
            this.Hide();
        }

        //加载所需要显示的数据
        private void result1_Load(object sender, EventArgs e)
        {
            string nextbirthday = DataContainer.Nextbirthday;
            int days = DataContainer.Data1;
            int day2 = DataContainer.Data2;
            string next_birthday = DataContainer.Nextbirthday;
            string next_birthday_before = GetPreviousDate(next_birthday, day2);
            string planday = DataContainer.Planday;
            label1.Text = "下次生日日期：" + nextbirthday;
            label2.Text = "距离今天天数："+days+"天";
            label3.Text = "距离下次生日前"+day2+"天的日期："+ next_birthday_before;
            label4.Text = "预计制定计划的日期：" + planday;
        }

        public static string GetPreviousDate(string dateStr, int days)
        {
            // 尝试解析输入字符串为 DateTime
            if (DateTime.TryParse(dateStr, out DateTime date))
            {
                // 计算 n 天前的日期
                DateTime previousDate = date.AddDays(-days);

                // 以字符串格式返回 yyyy-MM-dd
                return previousDate.ToString("yyyy-MM-dd");
            }
            else
            {
                return "输入的日期格式无效";
            }
        }
    }
}
